<%@ page language="java" pageEncoding="UTF-8"
         contentType="text/html;charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    request.setAttribute("basePath", basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp" %>
<%@ include file="/resources/js/wechat/_wechatui.jsp" %>
<%@ include file="/resources/js/easyui/_viewJS.jsp" %>
<!DOCTYPE>
<html>
<head>
    <title>上传LOGO商标</title>
    <script src="${basePath}resources/js/wechat/js/jquery-2.1.1.min.js"></script>
    <script src="${basePath}resources/js/wechat/js/ajaxfileupload.js"></script>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
    <a href="javascript:history.go(-1);" class="top_fh">上传LOGO商标</a>
</header>
<!-- header end -->

<div class="page nb_page">
    <div class="sclogo_inner">
        <div>
            <img id="user_logo_img" src="${logourl}"
                 alt="">
        </div>
    </div>
    <div class="my_sclogobutton">
        <a href="JavaScript:;" id="upload_logo_wechat" class='cur'>上传</a>
    </div>
</div>

<!-- 上次logo弹窗 -->
<%--<div class="sclogopop ty_pop">
    <div class="popbg"></div>
    <div class="sclgpop_inner">
        <ul>
            <li><a id="test_open_img" href="JavaScript:;">拍照test</a></li>
            <li><a href="JavaScript:;" style="width: 100%; height:3rem; position:relative; ">
                <input style="width: 100%; height:3rem; opacity:0;position:absolute; left:0rem; "
                       id="userlogo" name="userlogo" type="file">从相册选择</a></li>
            <li><a  href="JavaScript:;">取消</a></li>
        </ul>
    </div>
</div>--%>
<!-- 上次logo弹窗 end -->

</body>
</html>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    wx.config({
        debug: false,
        appId: '${jsret.appid}',
        timestamp: '${jsret.timestamp}',
        nonceStr: '${jsret.nonceStr}',
        signature: '${jsret.signature}',
        jsApiList: ['chooseImage', 'uploadImage']
    });

    wx.ready(function () {

        var localid = "";

        $("#user_logo_img").click(function () {
            wx.chooseImage({
                count: 1, // 默认9
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                    localid = localIds[0];
                    $("#user_logo_img").attr("src", localid);
                }
            });
        });
        $("#upload_logo_wechat").click(function () {
            if (typeof(localid) == "undefined" || localid.length <= 0) {
                alert("请选择图片！");
            } else {
                wx.uploadImage({
                    localId: localid, // 需要上传的图片的本地ID，由chooseImage接口获得
                    isShowProgressTips: 1, // 默认为1，显示进度提示
                    success: function (res) {
                        var serverId = res.serverId; // 返回图片的服务器端ID
                        //当上传微信服务器成功后，跳转到后台服务器
                        if (typeof(serverId) == "undefined" || serverId.length <= 0) {
                            alert("请重新上传图片！");
                        } else {
                            $.ajax({
                                url: '${basePath}wechat/indivdual/uploadLogo',
                                type: 'POST',
                                data: {"mediaid": serverId},
                                error: function (response) {
                                    ViewHelper.func.ajaxWechatErrorMessage(response);
                                },
                                success: function (ret) {
                                    alert(ret.info);
                                    /* if (!ret.result) {
                                     alert('温馨提醒:'+ret.info);
                                     }else{
                                     alert("成功");
                                     }*/
                                }
                            });
                        }
                    }
                });
            }
        });

    });


 /*   //浏览图片
    $("#userlogo").change(function () {
        var file = this.files[0];
        if (file.type.match("image.*")) {
            var r = new FileReader();
            r.readAsDataURL(file);
            $(r).load(function () {
                $("#user_logo_img").attr("src", this.result);
            })
        } else {
            console.log("上传的不是图片");
        }
    });

    //上传图片
    $("#upload_logo_btn").click(function () {
        $.ajaxFileUpload({
            url: '${basePath}wechat/indivdual/uploadLogo',
            secureuri: true,
            fileElementId: 'userlogo',
            dataType: 'json',
            type: 'POST',
            success: function (data, status) {
                alert(data.info);
            }, error: function (data, status, e) {
                ViewHelper.func.ajaxWechatErrorMessage(e);
            }
        });
    });*/

</script>